Ext.define('AmpleHarvest.objects.chart.cExportable',
		{
			extend			: 'Ext.chart.Chart',
			requires		:
			[
				'AmpleHarvest.util.UrlBuilder'
			],
			initComponent	: function()
			{
				var obj_This = this;
				this.on('afterrender', function(view, record, item, index, e,
								eOpts)
						{
							this.getEl().on('contextmenu', function(event)
							{
								var menu = Ext.create('Ext.menu.Menu',
										{
											items	:
											[{
														text	: 'Export as gif',
														scope	: this,
														handler	: function()
														{
															obj_This.exporter(
																	this, "gif"
															);
														}
													},
													{
														text	: 'Export as jpg',
														scope	: this,
														handler	: function()
														{
															obj_This.exporter(
																	this, "jpg"
															);
														}
													},
													{
														text	: 'Export as png',
														scope	: this,
														handler	: function()
														{
															obj_This.exporter(
																	this, "png"
															);
														}
													},
													{
														text	: 'Export as tif',
														scope	: this,
														handler	: function()
														{
															obj_This.exporter(
																	this, "tif"
															);
														}
													}
											]
										}
								);

								menu.showAt(event.getXY());
								event.stopEvent();
							}
							);
						}
				);
				this.callParent();
			},
			exporter		: function(obj_Chart, str_Format)
			{
				// If svg is supported
				if (!str_Format)
				{
					str_Format = "jpg";
				}
				if (!Ext.isIE)
				{
					var arr_Params = [];

					var obj_Wrap;

					// NOTE: Here "this" is the dom
					// element!

					obj_Wrap = document.createElement('div');
					obj_Wrap
							.appendChild(obj_Chart.down('svg', true).cloneNode(true));

					arr_Params["svg"] = obj_Wrap.innerHTML;
					arr_Params["output_format"] = str_Format;

					var obj_Exporter = Ext
							.create('AmpleHarvest.util.cExporter');

					obj_Exporter.exportPostWithParams(
							AmpleHarvest.util.UrlBuilder.getSVG2ImageUrl(),
							arr_Params, true
					);
				}
				else
				{
					// Workaround for now
					Ext.Msg.alert("Supported only in Firefox.");
				}
			}
		}
);